package com.label.Utils.Common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.label.Dao.UserMapper;
import com.label.Model.Do.User;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class InfoUtil {

    private static JdbcTemplate oracleJdbc;
    private static UserMapper userMapper;

    @Resource
    @Qualifier("oracleJdbcTemplate")
    public void setOracleJdbc(JdbcTemplate oracleJdbc) {
        InfoUtil.oracleJdbc = oracleJdbc;
    }

    @Resource
    public void setUserMapper(UserMapper userMapper){InfoUtil.userMapper=userMapper;}

    public static String getUnitName(String unitId){
        Map<String,Object> res=oracleJdbc.queryForMap("select unit_name from unit where UNIT_ID="+unitId);
        return res.get("UNIT_NAME").toString();
    }

    public static String getSchoolName(String schoolId){
        Map<String,Object> res=oracleJdbc.queryForMap("select school_name from school where id="+schoolId);
        return res.get("SCHOOL_NAME").toString();
    }

    public static String getPersonsTheme(Long persons){
        Map<String,Object> res=oracleJdbc.queryForMap("select THEME from PERSONAS_PERSONAS where id="+persons);
        return res.get("THEME").toString();
    }

    public static String getDepartmentName(String departmentId){
        Map<String,Object> res=oracleJdbc.queryForMap("select department_name from WORKFLOW.department where department_id='"+departmentId+"'");
        return res.get("DEPARTMENT_NAME").toString();
    }

    public static String getClassName(String classId){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+classId+"' and label_id=10");
        return res.get("LABEL").toString();
    }

    public static String getMajorName(String majorId){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+majorId+"' and label_id=8");
        return res.get("LABEL").toString();
    }

    public static String getNationName(String nation){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+nation+"' and label_id=1");
        return res.get("LABEL").toString();
    }

    public static String getPoliticsName(String politics){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+politics+"' and label_id=3");
        return res.get("LABEL").toString();
    }

    public static String getClassPositionName(String classposition){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+classposition+"' and label_id=7");
        return res.get("LABEL").toString();
    }

    public static String getUnionPositionName(String unionposition){
        System.out.println(unionposition);
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+unionposition+"' and label_id=6");
        return res.get("LABEL").toString();
    }

    public static String getNativeCityName(String nativecity){
        System.out.println(nativecity);
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+nativecity+"' and label_id=5");
        return res.get("LABEL").toString();
    }

    public static String getNativeProvinceName(String nativeprovince){
        Map<String,Object> res=oracleJdbc.queryForMap("select label from label where value='"+nativeprovince+"' and label_id=4");
        return res.get("LABEL").toString();
    }

    public static String getUserName(String userId){
        return userMapper.selectOne(new QueryWrapper<User>().lambda().eq(User::getAccount,userId)).getUserName();
    }

}
